cmake_minimum_required(VERSION 3.20)
# project(MCP C VERSION 1.0.0 DESCRIPTION "MCP Client Project")
project(MCP C)

# 设置 C 标准
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 设置编译器标志
# 更好的编译器标志设置方式
if(MSVC)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
else()
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99")
endif()

# 在 Windows 上链接 ws2_32 库
if(WIN32)
    set(PLATFORM_LIBS ws2_32)
else()
    # Linux/Unix 平台需要 pthread 和网络库
    set(PLATFORM_LIBS pthread m)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200112L")
endif()

# include_directories(.)

# 添加所有源文件
set(SOURCE_FILES
        # client_win.c
        mcp_decode.c
        mcp_json.c
        mcp_encrypt.c
        mcp_logger.c
        mcp_tcp.c
        mcp_udp.c
        mcp_net_mgr.c
        mcp_service.c
        mcp_retry_send.h
        mcp_retry_send.c
        mcp_queue.h
        mcp_queue.c
        mcp_recv_mgr.h
        mcp_recv_mgr.c
        client.c
        mcp_cmap.c
        mcp_exception.c
        mcp_cmap.h
        mcp_exception.h
        platform/platform_timer.h
        platform/platform_timer.c
        example/device_info_example.c
        platform/comm_timer.h
        platform/comm_timer.c
        example/device_info_example.h
        mcp_queue_example.c
        my_media/mcp_tx.c
        my_media/mcp_media.h
        my_media/live_stream.c
        my_media/mcp_msg_queue.h
        my_media/mcp_msg_queue.c
        my_media/mcp_tx.h
        rtp/ps.c
        my_media/live_audio_video.c
        bm/sys_os.c
        media_test.c
        # client_lunix.c
        # 添加一个 Linux 兼容的 main 文件
)

# 创建可执行文件
add_executable(MCP ${SOURCE_FILES})

# 链接库
target_link_libraries(MCP ${PLATFORM_LIBS})

# 包含头文件目录（如果有的话）
target_include_directories(MCP PRIVATE .)
# 包含头文件目录（如果有的话）
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include)
    target_include_directories(MCP PRIVATE include)
endif()

# 设置调试选项
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")

# 在文件末尾添加
if(CMAKE_BUILD_TYPE)
    message(STATUS "Current build type: ${CMAKE_BUILD_TYPE}")
endif()

